package com.jackiechancinema.ssm.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jackiechancinema.ssm.bo.OrderDateBO;
import com.jackiechancinema.ssm.config.SystemContant;
import com.jackiechancinema.ssm.dao.OrderDateDao;
import com.jackiechancinema.ssm.entity.OrderDate;
import com.jackiechancinema.ssm.service.Inte.OrderDateService;
import com.jackiechancinema.ssm.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class OrderDateServiceImpl implements OrderDateService {
    @Autowired
    OrderDateDao orderDateDao;
    @Override
    public PageVo<OrderDate> page(OrderDateBO bo) {
        if(bo!=null){
            //1.组装查询条件
            OrderDate sc=new OrderDate();
            if(StringUtils.hasLength(bo.getUsername())){
                sc.setUsername(bo.getUsername());
            }
            if(bo.getType()!=null){
                sc.setType(bo.getType());
            }

            //2.开启分页插件
            PageHelper.startPage(bo.getPage(), bo.getLimit());
            //3.获取分页的查询结果
            PageInfo<OrderDate> pageInfo=new PageInfo<>(orderDateDao.queryAll(sc));
            //4.返回结果
            return new PageVo<OrderDate>(SystemContant.PAGE_R,"OK",pageInfo.getTotal(),pageInfo.getList());
        }
        return new PageVo<OrderDate>(SystemContant.PAGE_R,"OK",0,null);
    }
}
